
/*
 XMail OSAX -- Copyright (C) 2004, 2005, 2006, 2007 Jean-Baptiste LE STANG osax@lestang.org
 
	
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 */


#ifndef MAIL_UTILS_H
#define MAIL_UTILS_H

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "pcre.h"
#include "mail-algorithms.h"

#ifdef __cplusplus
extern "C" {
#endif
    
    typedef enum _XMailEncoderEnum {
        UTF8,
        ISOLatin1, 
        WINDOWS1252,
        USASCII,
    } XMailEncoderID;
    
    typedef enum {
        QuotedPrintableAlgorithm = 'Q',
        Base64Algorithm = 'B',
    } EncodingAlgorithm;
    
    
    typedef  char *(XMailEncoderFunction)(char * orig_str) ;
    typedef  char *(XMailEncoderSplitter)(char * orig_str) ;
    
    typedef struct _XMailEncoder {
        char * encoderName;
        XMailEncoderID encoderID;
        XMailEncoderFunction * encoderFunction;
        XMailEncoderSplitter * encoderSplitterFunction;
    }XMailEncoder;
    

    typedef struct _growing_buffer {
        char * data;
        unsigned int length;
        unsigned int current_length;
    } growing_buffer;
    
    char * findMimeWithExtension(char * extension);
    char * findMimeWithFilePath(const char * path);
    char * findFileNameWithFilePath(const char * path);
    void appendChar(growing_buffer * theMail,char c);
    void appendString(growing_buffer * theMail,char * theString);
    void appendBytesToString(growing_buffer * theMail,char * theString,unsigned int nbytes);
    void matchEmailAndName(char * subject,char ** name,char ** email);
    char * newbound(const char * input);
    
    char * encodeutf8(char * orig_str);
    char * encodeutf8With76Chars(char * orig_str);
    
    char * encodeiso88591(char * orig_str);
    char * encodeiso88591with76Chars(char * orig_str);
    
    char * encodewindows1252(char * orig_str);
    char * encodewindows1252with76Chars(char * orig_str);
    char * encodeusascii(char * orig_str);
    char * encodeusasciiwith76Chars(char * orig_str);
    
#ifdef __cplusplus
}
#endif

#endif